<?php
declare(strict_types=1);


namespace yanlongli\TypePHP;


/**
 * Class TypeString
 * @package yanlongli\TypePHP
 * @method TypeInt len()
 * @method TypeInt pos($str, int $offset = 0)
 */
class TypeString extends TypePHP
{

    /**
     * TypeString constructor.
     * @param $val
     */
    public function __construct($val)
    {
        $this->val = (string)$val;
    }


    /**
     * @param bool|float|int|string|TypeString $str
     * @return bool
     */
    public function eq(self|string|int|bool|float $str): bool
    {
        return $this->_eq($str, false);
    }

    /**
     * @param bool|float|int|string|TypeString $str
     * @param bool $ieq
     * @return bool
     */
    protected function _eq(self|string|int|bool|float $str, $ieq = false): bool
    {
        return ($str instanceof TypePHP) ?
            (
            $ieq ?
                $str->_to() === $this->val :
                $str->_to() == $this->val
            ) :
            (
            $ieq ?
                $str === $this->val :
                $str == $this->val
            );
    }

    /**
     * @param bool|float|int|string|TypeString $str
     * @return bool
     */
    public function ieq(self|string|int|bool|float $str): bool
    {
        return $this->_eq($str, true);
    }

    public function __call($name, $arguments)
    {
        if (function_exists($funcName = 'mb_str' . mb_strtolower($name))) $funcName(...$arguments);


        return ('mb_str' . mb_strtolower($name))(...$arguments);
    }

}
